﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t205Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t205_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t205Mgr mgr = new t205Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t205(e.Parameters[t205_Filter.ParamPrefix]));
            IList<t205> list = mgr.FindAllByPage_t205(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t205_Filter.ParamPrefix]);
            t205_MainStore.DataSource = list;
            t205_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t205Mgr mgr = new t205Mgr();
            RowSelectionModel sm = t205_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t205 _t205 = new t205();
                _t205.t205_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t205(_t205))
                {
                    log.Debug("t205中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t205_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t205Mgr mgr = new t205Mgr();
            t205 _t205 = new t205();
            if (Hid.Text.Length > 0)
                _t205 = mgr.FindById_t205(int.Parse(Hid.Text));
            
			_t205.t205_01 = Txtt205_01.Text.Trim();
			_t205.t205_71 = Txtt205_71.Text.Trim();
			_t205.t205_02 = Txtt205_02.Text.Trim();
			_t205.t205_72 = Txtt205_72.Text.Trim();
			_t205.t205_73 = Txtt205_73.Text.Trim();
			_t205.t205_03 = Txtt205_03.Text.Trim();
			_t205.t205_04 = Txtt205_04.Text.Trim();
			_t205.t205_05 = Txtt205_05.Text.Trim();
			_t205.t205_74 = Txtt205_74.Text.Trim();
			_t205.t205_75 = Txtt205_75.Text.Trim();
			_t205.t205_06 = Txtt205_06.Text.Trim();
			_t205.t205_07 = Txtt205_07.Text.Trim();
			_t205.t205_08 = Txtt205_08.Text.Trim();
			_t205.t205_76 = Txtt205_76.Text.Trim();
			_t205.t205_77 = Txtt205_77.Text.Trim();
			_t205.t205_09 = Txtt205_09.Text.Trim();
			_t205.t205_10 = Txtt205_10.Text.Trim();
			_t205.t205_78 = Txtt205_78.Text.Trim();
			_t205.t205_11 = Txtt205_11.Text.Trim();
			_t205.t205_79 = Txtt205_79.Text.Trim();
			_t205.t205_80 = Txtt205_80.Text.Trim();
			_t205.t205_12 = Txtt205_12.Text.Trim();
			_t205.t205_13 = Txtt205_13.Text.Trim();
			_t205.t205_14 = Txtt205_14.Text.Trim();
			_t205.t205_81 = Txtt205_81.Text.Trim();
			_t205.t205_82 = Txtt205_82.Text.Trim();
			_t205.t205_15 = Txtt205_15.Text.Trim();
			_t205.t205_16 = Txtt205_16.Text.Trim();
			_t205.t205_83 = Txtt205_83.Text.Trim();
			_t205.t205_84 = Txtt205_84.Text.Trim();
			_t205.t205_85 = Txtt205_85.Text.Trim();
			_t205.t205_86 = Txtt205_86.Text.Trim();
			_t205.t205_87 = Txtt205_87.Text.Trim();
			_t205.t205_17 = Txtt205_17.Text.Trim();
			_t205.t205_70 = Txtt205_70.Text.Trim();
			_t205.t205_18 = Txtt205_18.Text.Trim();
			_t205.t205_19 = Txtt205_19.Text.Trim();
			_t205.t205_20 = Txtt205_20.Text.Trim();
			_t205.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t205(_t205);
            else
                isok = mgr.Add_t205(_t205);
            if (isok)
            {
                t205_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t205中执行了保存（插入或修改），并成功");
                t205_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}